function ImportStatusJsWindowOnLoad()
{
window.attachEvent("onbeforeunload", window_onbeforeunload);
setTimeout(checkStatus, 1000);
}

window.attachEvent('onload', ImportStatusJsWindowOnLoad);

function checkStatus()
{
var statusDocument = window.dialogArguments.document.StatusFrame;
var formDocument = window.dialogArguments.document.FormFrame;
var uploadForm = formDocument.UploadForm;
var importJobId = uploadForm.importJobId.value;

if (statusDocument.divStatus != null)
{
window.detachEvent("onbeforeunload", window_onbeforeunload);
butBegin.disabled = false;
divMessage.innerText = statusDocument.divStatusMessage.innerText;

if (statusDocument.divStatus.innerText == "failure")
{
imgIcon.src = "/_imgs/error/notif_icn_critical.png";
}

var sMessages = statusDocument.divMoreMessages.innerText;
if (sMessages != "")
{
txtMessages.innerText = sMessages.replace(/\/r\/n/g, "\r\n");
}
divProgress.style.display = "none";
divMoreMessages.style.display = "inline";
}
else
{
var iTotalProcessed, iTotalBlocks;


var oProgressRetrieveCommand = new RemoteCommand("ImportJob", "Retrieve");

oProgressRetrieveCommand.ErrorHandler = emptyErrorHandler;
oProgressRetrieveCommand.SetParameter("id", importJobId);
var columns = new Array();
columns.type = "string";
columns[0] = "data";
oProgressRetrieveCommand.SetParameter("columns", columns);
var oResult = oProgressRetrieveCommand.Execute();


if (oResult.Success)
{
var oImportJob = oResult.ReturnValue.importjob;

var oDataXml = loadXmlDocument(oImportJob.data);
iTotalBlocks = oDataXml.selectNodes("//entity").length +
oDataXml.selectNodes("//node").length +
oDataXml.selectNodes("//setting").length +
oDataXml.selectNodes("//securityrole").length +
oDataXml.selectNodes("//workflow").length;
iTotalProcessed = oDataXml.selectNodes("//entity[@result]").length +
oDataXml.selectNodes("//node[@result]").length +
oDataXml.selectNodes("//setting[@result]").length +
oDataXml.selectNodes("//securityrole[@result]").length +
oDataXml.selectNodes("//workflow[@result]").length;


var iPercentage = iTotalProcessed *100 /iTotalBlocks;
if (iPercentage > 100)
{
iPercentage = 100;
}
divFill.style.pixelWidth = divFillBg.style.pixelWidth * iPercentage / 100;
}
setTimeout(checkStatus, 1000);
}
}

function applychanges()
{
window.detachEvent("onbeforeunload", window_onbeforeunload);
window.close();
}
function window_onbeforeunload()
{
event.returnValue = LOCID_IMPORT_DLG_CLOSE_CNFRM;
}
